var Opera=navigator.userAgent.toLowerCase().indexOf("opera")!=-1?true:false;
var Opera8=navigator.userAgent.toLowerCase().indexOf("opera 8")!=-1?true:false;
var Opera7=navigator.userAgent.toLowerCase().indexOf("opera 7")!=-1?true:false;
var Opera6=navigator.userAgent.toLowerCase().indexOf("opera 6")!=-1?true:false;
var Opera5=navigator.userAgent.toLowerCase().indexOf("opera 5")!=-1?true:false;
var Opera4=navigator.userAgent.toLowerCase().indexOf("opera 4")!=-1?true:false;
var Netscape4=navigator.userAgent.toLowerCase().indexOf("mozilla/4.79")!=-1?true:false;
var Netscape6=navigator.userAgent.toLowerCase().indexOf("netscape6")!=-1?true:false;
var Netscape7=navigator.userAgent.toLowerCase().indexOf("netscape/7")!=-1?true:false;
var Netscape8=navigator.userAgent.toLowerCase().indexOf("netscape/8")!=-1?true:false;
var MozillaFireFoxRev0=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:0")!=-1?true:false);

var MozillaFireFoxRev10=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:1.0")!=-1?true:false);

var MozillaFireFoxRev11=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:1.1")!=-1?true:false);

var MozillaFireFoxRev12=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:1.2")!=-1?true:false);

var MozillaFireFoxRev13=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:1.3")!=-1?true:false);

var MozillaFireFoxRev14=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:1.4")!=-1?true:false);

var MozillaFireFoxRev15=(navigator.userAgent.toLowerCase().indexOf("mozilla")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false) && (navigator.userAgent.toLowerCase().indexOf("rv:1.5")!=-1?true:false);

var MozillaFireFoxRevOlder15 = MozillaFireFoxRev0 || MozillaFireFoxRev10 || MozillaFireFoxRev11 || MozillaFireFoxRev12 || MozillaFireFoxRev13 || MozillaFireFoxRev14 || MozillaFireFoxRev15;
var IE4=navigator.userAgent.toLowerCase().indexOf("msie 4")!=-1?true:false;

var PowUploadLastFileIndex = 0;
var MAX_UPLOADING_FILES	= 10;
function AddFileInput(parentObjID)	{
	if(Opera7 || Opera6 || Opera5)
	{
		window.alert("This feature not supported in your browser!");
		return;
	};

	PowUploadLastFileIndex	= (PowUploadLastFileIndex < 0)	? 0 : PowUploadLastFileIndex;
	var parentObj = document.getElementById(parentObjID);
	//alert(PowUploadLastFileIndex);
	if (PowUploadLastFileIndex >= MAX_UPLOADING_FILES)	{
		//new Element.hide( 'addButton' );
		alert('Impossibile aggiungere altri files!');
	} else {
		PowUploadLastFileIndex ++;
		//new Element.show( 'addButton' );
		var newFileIndex = PowUploadLastFileIndex;
		var newFileInputID = 'filediv' + newFileIndex;
		var newFileInput = document.createElement('div');
		newFileInput.setAttribute("id", newFileInputID);
		newFileInput.setAttribute("class", "withPadding2");
		newFileInput.style.position	= "relative";
		numberingField			= (newFileIndex < 10)	? '0' + newFileIndex : newFileIndex;
		fWidth	= (newFileIndex < 10)	? '50' : '50';
		newFileInput.innerHTML = '';
		newFileInput.innerHTML += '<input type="file" name="file' + newFileIndex + '"  id="file' + newFileIndex + '" size="' + fWidth + '">';
		//newFileInput.innerHTML += '&nbsp;&nbsp;<input onClick="javascript: ClearInputField(\'file' + newFileIndex + '\');" type="button" value="Clear" class="clearButton">';
		newFileInput.innerHTML += '&nbsp;&nbsp;<input onClick="javascript:removeFileInput(\'' + newFileInputID + '\');" type="button" value="Remove" class="removeButton">';
		//newFileInput.innerHTML += '<div id="preview' + newFileIndex + '" style="position:relative;top:-15px;left:600px;" class="white01"><img id="imagepw' + newFileIndex + '" style="display:none"></div>';
		//newFileInput.innerHTML += '<br>';
		parentObj.appendChild(newFileInput);
		//Uncomment line below to add new FileInput in front of other inputs.
		//parentObj.insertBefore(newFileInput, parentObj.firstChild);
	}
}

/****************************************
	Aggiungi Campo per upload
	di documenti da inserire
	in contenuti
*****************************************/
function addFileForContent(parentObjID)	{
	if(Opera7 || Opera6 || Opera5)
	{
		window.alert("This feature not supported in your browser!");
		return;
	};

	PowUploadLastFileIndex	= (PowUploadLastFileIndex < 0)	? 0 : PowUploadLastFileIndex;
	var parentObj = document.getElementById(parentObjID);
	//alert(PowUploadLastFileIndex);
	if (PowUploadLastFileIndex >= MAX_UPLOADING_FILES)	{
		//new Element.hide( 'addButton' );
		alert('Impossibile aggiungere altri files!');
	} else {
		PowUploadLastFileIndex ++;
		//new Element.show( 'addButton' );
		var newFileIndex = PowUploadLastFileIndex;
		var newFileInputID = 'filediv' + newFileIndex;
		var newFileInput = document.createElement('div');
		newFileInput.setAttribute("id", newFileInputID);
		newFileInput.setAttribute("class", "withPadding2");
		newFileInput.style.position	= "relative";
		numberingField			= (newFileIndex < 10)	? '0' + newFileIndex : newFileIndex;
		fWidth	= (newFileIndex < 10)	? '50' : '50';
		tWidth	= (newFileIndex < 10)	? '250' : '250';
		newFileInput.innerHTML = '';
		newFileInput.innerHTML += '<input type="file" name="file' + newFileIndex + '"  id="file' + newFileIndex + '" size="' + fWidth + '">';
		newFileInput.innerHTML += '&nbsp;&nbsp; <a href="javascript:removeFileInput(\'' + newFileInputID + '\');" class="strong bbCode14 black01">X</a>';
		parentObj.appendChild(newFileInput);
		//Uncomment line below to add new FileInput in front of other inputs.
		//parentObj.insertBefore(newFileInput, parentObj.firstChild);
	}
}

// Function to remove file input
function removeFileInput(objToRemoveID)
{
	if(Opera6 || Opera5)
	{
		window.alert("This feature not supported in your browser!");
		return;
	};
	var ObjToRemove = document.getElementById(objToRemoveID);
	var parentObj = ObjToRemove.parentNode;
	parentObj.removeChild(ObjToRemove);
	PowUploadLastFileIndex --;
}

// Function to clear file input
function ClearInputField(inputID)
{
	if(Opera4 || Opera5 || Opera6 || Opera7 || Netscape4 || Netscape6)
	{
		window.alert("This feature not supported in your browser!");
		return;
	};
	var inputObj = document.getElementById(inputID);
	var parentObj = inputObj.parentNode;
	var nextObj = inputObj.nextSibling;
	var EmptyFileInput;

	if(!Opera && inputObj.outerHTML)
	{

		EmptyFileInput = document.createElement(inputObj.outerHTML);
		parentObj.removeChild(inputObj);
		parentObj.insertBefore(EmptyFileInput, nextObj);

	}
	else //for FireFox that doesn't supports outerHTML property
	{
		var tmpParentObj = document.createElement('font');
		tmpParentObj.appendChild(inputObj);
		var innerHTMLCode = tmpParentObj.innerHTML;
		tmpParentObj.removeChild(inputObj);
		EmptyFileInput = document.createElement('font');
		EmptyFileInput.innerHTML = innerHTMLCode;
		parentObj.insertBefore(EmptyFileInput.childNodes[0], nextObj);

	}
}
//__________________________________________________________________________________________